package com.sanyang.pda.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.sanyang.pda.adapter.PopSelectAdapter;
import com.sanyang.pda.bean.SelectBean;
import com.wangshen.projectbase.R;

import java.util.List;



public class SelectPop extends Dialog {
    private Context context;
    private List<SelectBean> strings;
    private Onclick onclick;
    PopSelectAdapter adapter;
    public SelectPop(Context context,  Onclick onclick) {
        super(context);
        this.context = context;
        this.onclick = onclick;
        initView();
    }

    public void initView(){
        View view= LayoutInflater.from(context).inflate(R.layout.pop_select,null);
        RecyclerView recyclerView=view.findViewById(R.id.rv_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        PopSelectAdapter adapter=new PopSelectAdapter(R.layout.item_pop_select_list,strings);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if (onclick != null){
                    onclick.onClick(strings.get(position));
                }
                dismiss();
            }
        });
        setContentView(view);

    }


    public void show(List<SelectBean> string) {
        super.show();
        this.strings=string;
        initView();
    }

    public interface Onclick{
        void onClick(SelectBean content);
    }
}
